Skip to content

syscall: traverse unstatable intermediate directories - #1171

Merged
steadytao merged 11 commits into
RsyncProject:masterfrom
seks99x:fix-unstatable-intermediate-dir
Nov 17, 2026
Merged

steadytao merged 11 commits into
RsyncProject:masterfrom
seks99x:fix-unstatable-intermediate-dir

Conversation

@seks99x

@seks99x seks99x commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #1170

Android FUSE mount roots such as /storage/emulated can return ENOENT from fstatat() even though openat() can traverse the directory. The secure path walker previously stopped at the failed stat.

When an intermediate component returns ENOENT, the walker now tries to open that single component with its normal directory traversal flags plus O_NOFOLLOW. A successful descriptor rejoins the existing path tracking and confinement path. A failed open preserves its own error. Leaf handling is unchanged. Regression uses a deterministic test build to reproduce the Android behaviour. It covers absolute and relative traversal, missing descendants, intermediate symlink refusal and --confine-root enforcement after the fallback.

@seks99x
seks99x force-pushed the fix-unstatable-intermediate-dir branch from 088b927 to a9d5955 Compare November 13, 2026 20:32
@seks99x

seks99x commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

I think this could be raced. No well parent-held fd and the path could be called relatively containing a / . I'll fix it.

@seks99x
seks99x force-pushed the fix-unstatable-intermediate-dir branch from a9d5955 to 5074f19 Compare November 13, 2026 20:56
@seks99x

seks99x commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

@kkrrz test please.

@kkrrz

kkrrz commented Nov 13, 2026

Copy link
Copy Markdown

@seks99x
Tested 5074f19 on Termux (Android 14, aarch64) without --insecure-links.
Local copy, cd + ./ destination, remote pull (user@server:/path/ -> /storage/emulated/0/Documents/),
and a copy into the Termux home directory all work:

$ ./rsync -v ~/t.txt /storage/emulated/0/Documents/
t.txt
sent 88 bytes  received 35 bytes  246.00 bytes/sec

$ cd /storage/emulated/0/Documents && ~/rsync-pr/rsync -v ~/t.txt ./
t.txt
sent 88 bytes  received 35 bytes  246.00 bytes/sec

Released 3.5.2 fails on these commands with change_dir#1 ... failed: No such file or directory (2) at /storage/emulated.

Note: in my local build, configure did not define SEARCH_ONLY_DIRFD_FLAG, so the walk fell back to
O_RDONLY|O_DIRECTORY and failed with EACCES opening / (same as #1050).
After adding #define SEARCH_ONLY_DIRFD_FLAG O_PATH to config.h (as in the Termux package build), all of the above succeed.
This seems specific to my ad-hoc configure run (I had to pass --build/--host manually), not to this PR.

Thanks for the fix!

@seks99x

seks99x commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

Thanks for testing!

@seks99x
seks99x force-pushed the fix-unstatable-intermediate-dir branch 2 times, most recently from 62b98a9 to 0da0cbe Compare November 15, 2026 17:33
On Android, intermediate FUSE mount roots such as /storage/emulated fail
fstatat(AT_SYMLINK_NOFOLLOW) with ENOENT (via vfs_getattr) even though
their VFS dentry exists and resolves during path traversal.

When an intermediate component (is_last == 0) in ona_open() fails fstatat()
with ENOENT, fall back to opening the single component directly via
openat(dfd, comp, dir_traverse_flags | O_NOFOLLOW). Because O_PATH |
O_DIRECTORY | O_NOFOLLOW pins the VFS directory dentry without invoking
vfs_getattr(), it traverses un-stat-able intermediate mount points while
preserving atomic single-component O_NOFOLLOW/O_DIRECTORY checks,
abspath tracking, and confinement.
@steadytao
steadytao force-pushed the fix-unstatable-intermediate-dir branch from 0da0cbe to 84bc3d2 Compare November 16, 2026 04:35
@steadytao steadytao changed the title syscall: handle un-stat-able intermediate mount dirs in ona_open() syscall: traverse unstatable intermediate directories Nov 16, 2026
@steadytao
steadytao enabled auto-merge (squash) November 16, 2026 04:48
@steadytao steadytao added the Bug Confirmed incorrect behaviour or failure label Nov 16, 2026
@steadytao steadytao added this to the 4.0.0 milestone Nov 16, 2026
@seks99x

seks99x commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Im not with using building patched version , tests could be broke easily if the code is changed. Also please do not remove the test comments we can rather clean it, im not a big fan of them but some edge cases could be forgot or become too complex to read without a proper documentation/hinting.

@steadytao

Copy link
Copy Markdown
Member

Im not with using building patched version , tests could be broke easily if the code is changed. Also please do not remove the test comments we can rather clean it, im not a big fan of them but some edge cases could be forgot or become too complex to read without a proper documentation/hinting.

Missing or ambiguous patch targets now fail the test. The injection is documented; comments that just narrate the code will be staying out.

@steadytao
steadytao disabled auto-merge November 16, 2026 19:31
@steadytao
steadytao enabled auto-merge (squash) November 16, 2026 19:32
@steadytao
steadytao disabled auto-merge November 16, 2026 19:57
@steadytao
steadytao enabled auto-merge (squash) November 16, 2026 19:58
@steadytao
steadytao disabled auto-merge November 17, 2026 04:02
@steadytao
steadytao merged commit 64e6b1d into RsyncProject:master Nov 17, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Confirmed incorrect behaviour or failure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.5.2] Android/Termux: destination under /storage/emulated/0 fails with ENOENT (intermediate path component not stat-able)

3 participants